package com.dongdongshop.controller;

import com.dongdongshop.admin.vo.ItemCatVO;
import com.dongdongshop.common.Result;
import com.dongdongshop.service.ItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("itemcat")
public class CatController {
    @Autowired
    private ItemCatService itemCatService;

    @PostMapping("getByParentId")
    public Result getByParentId(@RequestParam Long parentId){
        List<ItemCatVO> vo = itemCatService.getByParentId(parentId);
        return Result.OK().setData(vo);
    }
    
    @PostMapping("getId")
    public Result getId(@RequestParam Long parentId){
        ItemCatVO vo = itemCatService.getId(parentId);
        return Result.OK().setData(vo);
    }

    @PostMapping("addCatVO")
    public Result addCatVO(@RequestBody ItemCatVO catVO){
        itemCatService.add(catVO);
        return Result.OK();
    }

    @PostMapping("getById")
    public Result getById(@RequestParam Long id){
        ItemCatVO cat = itemCatService.getById(id);
        return Result.OK().setData(cat);
    }

    @PostMapping("updateCat")
    public Result updateCat(@RequestBody ItemCatVO catVO){
        itemCatService.update(catVO);
        return Result.OK();
    }

    @DeleteMapping("delete")
    public Result delete(@RequestParam Long[] ids) {
        itemCatService.delete(ids);
        return Result.OK();
    }
    @PostMapping("getAll")
    public Result getAll(){
       List<ItemCatVO> itemCatVOList= itemCatService.getAll();
        return Result.OK().setData(itemCatVOList);
    }
}
